<template>
  <div class="container">
    <div class="header">
      <div class="headerContent">
        <div class="left">后台管理</div>
        <div class="right">
          <p class="loginInfo">
            {{ userStore.userInfo?.userName }}
          </p>
          <el-dropdown>
            <span>
              <el-icon size="30" color="var(--Nav-rightleft-color)">
                <Avatar />
              </el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="() => toHome()">回到主页</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item @click="() => toBusiness()">业务服务</el-dropdown-item>
                <el-dropdown-item @click="() => exit()">退出账号</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </div>
    <ThemeDialog ref="themeDialogVisible" />
  </div>
</template>

<script setup>
import { ref, computed,reactive, onMounted } from 'vue';
import { Avatar } from '@element-plus/icons-vue'
import { useRoute, useRouter } from 'vue-router';
import useUserStore from '../../store/user';
import { ElMessage } from 'element-plus';
// 用户存储
let userStore = useUserStore()
// 路由
const $router = useRouter()
// 弹窗
// 返回首页
const toHome = () => {
  $router.push("/home")
}
const toBusiness = () => {
  if (userStore.getVISIT()) {
    $router.push({
      path: '/business',
      query: {
        companyId: userStore.getVISIT()
      }
    })
  }
  else{
    ElMessage({
      type:"info",
      message:"无访问公司记录，即将前往首页"
    })
    setTimeout(()=>{
      $router.push("/home")
    },1000)
  }
}
// 退出登录
const exit = () => {
  useUserStore().logout()
  ElMessage({
    message: '退出成功',
    type: 'success'
  })
  $router.replace('/login')
}

onMounted(() => {
 
}
)
</script>

<style scoped lang="scss">
@use '@/styles/manageNav.scss';
</style>
